<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

if(isset($_SESSION['u_nic'])&&isset($_GET['id'])) {
	$title = "Gestion d'un hébergement";
	$tplinc = "panel-hebergement";
	$tpl->assign(array(
		'iconesleft' => 2,
		'prod' => '0',
		'prod_id' => intval($_GET['id'])
	));
	include('php/lib/panel_inc.php');
	$heberg_current = intval($_GET['id']);
	$infos_heberg = mysql_query("SELECT comptes_heberg.u_nic,
										comptes_heberg.id,
										comptes_heberg.uid_linux,
										comptes_heberg.user_linux,
										comptes_heberg.serveur_apache,
										comptes_heberg.serveur_mysql,
										comptes_heberg.offre,
										comptes_heberg.etat,
										comptes_heberg.dom_lie,
										comptes_heberg.espacedisk AS c_espacedisk,
										comptes_heberg.bandepassante AS c_bandepassante,
										comptes_heberg.mails AS c_mails,
										comptes_heberg.mysql AS c_mysql,
										comptes_heberg.ftp AS c_ftp,
										comptes_heberg.dom_inclus,
										comptes_heberg.alias_mails AS c_alias_mails,
										UNIX_TIMESTAMP(comptes_heberg.create),
										UNIX_TIMESTAMP(comptes_heberg.expire),
										comptes_domain.domaine,
										offre_surmesure.id_heberg,
										offre_surmesure.espacedisk as o_espacedisk_,
										offre_surmesure.bandepassante as o_bandepassante_,
										offre_surmesure.bases_mysql as o_bases_mysql_,
										offre_surmesure.comptes_mails as o_comptes_mails_,
										offre_surmesure.alias_mails as o_alias_mails_,
										offre_surmesure.user_ftp as o_user_ftp_,
										offre_surmesure.doms as o_doms_,
										offre_heberg.id_offre,
										offre_heberg.name_offre,
										offre_heberg.espacedisk AS o_espacedisk,
										offre_heberg.bandepassante AS o_bandepassante,
										offre_heberg.bases_mysql AS o_mysql,
										offre_heberg.comptes_mails AS o_mails,
										offre_heberg.alias_mails AS o_alias_mails,
										offre_heberg.user_ftp AS o_ftp
										FROM comptes_heberg 
										LEFT JOIN offre_heberg
										ON comptes_heberg.offre = offre_heberg.id_offre
										LEFT JOIN comptes_domain
										ON comptes_heberg.dom_lie = comptes_domain.id
										LEFT JOIN offre_surmesure
										ON comptes_heberg.id = offre_surmesure.id_heberg
										WHERE comptes_heberg.id='".$heberg_current."' AND comptes_heberg.u_nic='".$_SESSION['u_nic']."'")or die(mysql_error());
	if(mysql_num_rows($infos_heberg) == 1) {
		$infos_heberg = mysql_fetch_array($infos_heberg);
		$parse = 1;	
		// Espace Disque
		if($infos_heberg['o_espacedisk'] == "") {
			$infos_heberg['o_espacedisk'] = $infos_heberg['o_espacedisk_'];
			$infos_heberg['o_bandepassante'] = $infos_heberg['o_bandepassante_'];
			$infos_heberg['o_bases_mysql'] = $infos_heberg['o_bases_mysql_'];
			$infos_heberg['o_comptes_mails'] = $infos_heberg['o_comptes_mails_'];
			$infos_heberg['o_alias_mails'] = $infos_heberg['o_alias_mails_'];
			$infos_heberg['o_user_ftp'] = $infos_heberg['o_user_ftp_'];
			$infos_heberg['o_doms'] = $infos_heberg['o_doms_'];
		}
		
		$infos_heberg['c_espacedisk_field'] = round(($infos_heberg['c_espacedisk']*200)/$infos_heberg['o_espacedisk']);
		if($infos_heberg['c_espacedisk_field'] > 200) {
			$infos_heberg['c_espacedisk_field'] = 200;
		}
		if($infos_heberg['o_espacedisk'] > 1024) {
			$infos_heberg['o_espacedisk'] = round(($infos_heberg['o_espacedisk']/1024),2).'Go';
			$infos_heberg['c_espacedisk'] = round(($infos_heberg['c_espacedisk']/1024),2).'Go';
		}
		else {
			$infos_heberg['o_espacedisk'] = round($infos_heberg['o_espacedisk'],2).'Mo';
			$infos_heberg['c_espacedisk'] = round($infos_heberg['c_espacedisk'],2).'Mo';
		}
		// Bande Passante
		$infos_heberg['c_bandepassante_field'] = round((($infos_heberg['c_bandepassante']/1024/1024)*200)/$infos_heberg['o_bandepassante']);
		if($infos_heberg['c_bandepassante_field'] > 200) {
			$infos_heberg['c_bandepassante_field'] = 200;
		}
		if($infos_heberg['o_bandepassante'] > 1024) {
			$infos_heberg['o_bandepassante'] = round(($infos_heberg['o_bandepassante']/1024),3).'Go';
			$infos_heberg['c_bandepassante'] = round(($infos_heberg['c_bandepassante']/1024/1024/1024),3).'Go';
		}
		else {
			$infos_heberg['o_bandepassante'] = round($infos_heberg['o_bandepassante'],2).'Mo';
			$infos_heberg['c_bandepassante'] = round($infos_heberg['c_bandepassante']/1024/1024,2).'Mo';
		}
		//////
		if($infos_heberg['domaine'] == "") {
			$domaine_principal = $infos_heberg['user_linux'].".breizh-web.net";
		}
		else {
			$domaine_principal = $infos_heberg['domaine'];
		}
			
		
		$tpl->assign(array(
			"create" => date('d/m/Y H:i',$infos_heberg['UNIX_TIMESTAMP(comptes_heberg.create)']),
			"expire" => date('d/m/Y H:i',$infos_heberg['UNIX_TIMESTAMP(comptes_heberg.expire)']),
			"user_linux" => $infos_heberg['user_linux'],
			"user_linux" => $infos_heberg['user_linux'],
			"offre" => $infos_heberg['name_offre'],
			"etat" => $infos_heberg['etat'],
			"serveur_ftp_i" => $server[$infos_heberg['serveur_apache']]['ip'],
			"serveur_ftp_n" => $server[$infos_heberg['serveur_apache']]['ftp'],
			"serveur_mysql_i" => $server[$infos_heberg['serveur_mysql']]['ip'],
			"serveur_mysql_n" => $server[$infos_heberg['serveur_mysql']]['ns'],
			"c_espacedisk" => $infos_heberg['c_espacedisk'],
			"c_espacedisk_field" => $infos_heberg['c_espacedisk_field'],
			"o_espacedisk" => $infos_heberg['o_espacedisk'],
			"c_bandepassante" => $infos_heberg['c_bandepassante'],
			"c_bandepassante_field" => $infos_heberg['c_bandepassante_field'],
			"o_bandepassante" => $infos_heberg['o_bandepassante'],
			"o_ftp" => $infos_heberg['o_ftp'],
			"c_ftp" => $infos_heberg['c_ftp'],
			"c_mysql" => $infos_heberg['c_mysql'],
			"o_mysql" => $infos_heberg['o_mysql'],
			"c_mails" => $infos_heberg['c_mails'],
			"o_mails" => $infos_heberg['o_mails'],
			"c_alias_mails" => $infos_heberg['c_alias_mails'],
			"o_alias_mails" => $infos_heberg['o_alias_mails'],
			"id_offre" => $infos_heberg['id_offre'],
			"domaine_principal" => $domaine_principal,
			"dom_inclus" => $infos_heberg['dom_inclus'],
			"ns_prim" => $bzh_config['ns_prim'],
			"ns_sec" => $bzh_config['ns_sec'],
			"ns_mail" => $bzh_config['ns_mail'],
		));
		if($infos_heberg['dom_inclus'] > 0) {
			$tpl->assign(array(
			"load" => "new Effect.Shake(document.getElementById('dominc'))"
			));
		}	
		
	}
	else {
	echo mysql_num_rows($infos_heberg)."_".$heberg_current."_".$_SESSION['u_nic'];
	}
}
else { header("Location:/site/connexion.html"); }

?>